package me.yuzhou.weixin.util;

import java.util.Arrays;

import org.apache.commons.codec.digest.DigestUtils;

public class CheckUtil {
	
	private static final String token = "yuzho";
	
	public static boolean checkSignature(String signature, String timestamp, String nonce) {
		//1. 将token、timestamp、nonce三个参数进行字典序排序
		String[] arr = new String[]{token, timestamp, nonce};
		Arrays.sort(arr);
		
		//2. 将三个参数字符串拼接成一个字符串进行sha1加密
		StringBuffer content = new StringBuffer();
		for(int i=0; i<arr.length; i++){
			content.append(arr[i]);
		}
		
		String temp = DigestUtils.sha1Hex(content.toString());
		
		return temp.equals(signature);
	}

}
